package com.metadata_system.system.response;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.metadata_system.common.db.entity.UserOperationLog;
import com.metadata_system.common.enums.AllConst;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.context.annotation.ComponentScan;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@ComponentScan("com.metadata_system.common.db")
public class UserOperationLogResponse {
    private Integer id;
    private Object type;
    private String content;
    private String params;
    private String file;
    private String username;
    private Object role;
    private String ip;
    /**
     * 是否推送到ai-server: 0.否 1.是
     */
    private Object isPushAiServer;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    private Date createdTime;

    public static UserOperationLogResponse formatData(UserOperationLog userOperationLog){
        return UserOperationLogResponse.builder()
                .id(userOperationLog.getId())
                .ip(userOperationLog.getIp())
                .role(AllConst.IdName(userOperationLog.getRole(),AllConst.UserRoleMap))
                .username(userOperationLog.getUsername())
                .createdTime(userOperationLog.getCreatedTime())
                .type(AllConst.IdName(userOperationLog.getType(),AllConst.UserOperationTypeMap))
                .content(userOperationLog.getContent())
                .params(userOperationLog.getParams())
                .file(userOperationLog.getFile())
                .isPushAiServer(AllConst.IdName(userOperationLog.getIsPushAiServer(),AllConst.IsStatusArr))
                .build();
    }

    public static List<UserOperationLogResponse> formatData(List<UserOperationLog> userOperationLogs){
        List<UserOperationLogResponse> loginLogResponses=new ArrayList<>();
        for (UserOperationLog userOperationLog : userOperationLogs) {
            loginLogResponses.add(UserOperationLogResponse.formatData(userOperationLog));
        }
        return loginLogResponses;
    }
}
